<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/app/inventory.js',CClientScript::POS_BEGIN);?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'dispatchparts-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'dispatch'); ?>
		<?php echo $form->textField($model,'dispatch',array('size'=>15,'maxlength'=>15)); ?>
		<?php echo $form->error($model,'dispatch'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'counter'); ?>
		<?php echo $form->textField($model,'counter',array('value'=>$model->getNextCounter())); ?>
		<?php echo $form->error($model,'counter'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'warehouse'); ?>
		<?php echo $form->dropDownList($model,'warehouse',$model->getWarehouseList()); ?>
		<?php echo $form->error($model,'warehouse'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'partno'); ?>
                
                
                <?php echo $form->textField($model,'partno',array('size'=>60,'maxlength'=>75)); ?>
            <div class="model-data">
                <a id="search-part-link" href="#inventory-list" >Search...</a>                
            </div>
		<?php echo $form->error($model,'partno'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'partdesc'); ?>
		<?php echo $form->textArea($model,'partdesc',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'partdesc'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'quanity'); ?>
		<?php echo $form->textField($model,'quanity'); ?>
		<?php echo $form->error($model,'quanity'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'noprint'); ?>
		<?php echo $form->checkBox($model,'noprint'); ?>
		<?php echo $form->error($model,'noprint'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'price'); ?>
		<?php echo $form->textField($model,'price'); ?>
		<?php echo $form->error($model,'price'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'jobclass'); ?>
		<?php echo $form->textField($model,'jobclass',array('size'=>40,'maxlength'=>40)); ?>
		<?php echo $form->error($model,'jobclass'); ?>
	</div>

	<div class="row_buttons">
		<?php echo CHtml::submitButton('Save');?>
	</div>

<?php $this->endWidget(); ?>
        
                <div id="inventory-list">               
                </div>

         
       
        <?php Yii::app()->clientScript->registerScript('selectpart',<<<HERE
 
   Ext.onReady(function(){
   inventoryGrid.hide();
   win = Ext.widget('window', {
                title: 'Search Inventory',
                closeAction: 'hide',
                
                minHeight: 400,
                layout: 'fit',
                resizable: true,
                modal: true,
                contentEl:'inventory-list'
            });
            
    $('#search-part-link').click(function(){
            inventoryGrid.show();
    
            win.show();
    });
        
       inventoryGrid.getSelectionModel().on('selectionchange', function(sm, selectedRecord) {
            if (selectedRecord.length) {
                $('#Dispatchparts_partno').val(selectedRecord[0].data.partno);
                $('#Dispatchparts_partdesc').val(selectedRecord[0].data.description);
                $('#Dispatchparts_price').val(selectedRecord[0].data.pricea);
                win.hide();
            }
        });
    });
HERE
                ,CClientScript::POS_END);?>
</div><!-- form -->